<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        h1{
            margin: 10px;
        }
        .container{
            width: 600px;
            margin: 0 auto;
        }
        .container div.content{
            padding: 25px;
            background-color: pink;
            display: flex;
            flex-direction: column ;
        }
        .container div.name{
            margin-bottom: 10px;
        }
        .container div.name input{
            height: 30px;
            border: 0;
            border-radius: 4px;
        }
        .container textarea{
            border: 0;
            border-radius: 4px;
            height: 100px;
            margin-left: 36px;
        }
        .container div.type{
            position: relative;
            margin-top: 10px;
            display: flex;
            height: 60px;
            flex-direction: row-reverse;
        }
        .container div.type input {
            margin-right: 10px;
        }
        .container div.content button{
            position: absolute;
            top: 30px;
            right: 0;
            width: 60px;
            height: 30px;
            background-color: blueviolet;
            color: #fff;
            line-height: 30px;
            border: 0 ;
            border-radius: 4px;
        }
        input,textarea{
            padding-left: 10px;
        }

        ul.history{
            margin-left: 20px;
        }
        ul.history li{
            list-style: none;
            padding: 10px;
            border-bottom: 1px solid #eee;
            background-color: #fff;
            border-radius: 6px;
            margin-top: 10px;
        }
        ul.history span.name{
            font-size: 16px;
        }
        ul.history span.time{
            font-size: 12px;
            color: gray;
            margin-left: 10px;
        }
        ul.history p.content{
            margin-top: 10px;
            margin-left: 20px;
            color: gray;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>留言板</h1>
        <div class="content">
            <div class="name">
                <span>昵称</span>
                <input type="text" class="nickName">
            </div>
            <textarea class="textContent"></textarea>
            <div class="type">
                <span>匿名</span>
                <input type="checkbox" class="checkbox">
                <button>
                    发表
                </button>
            </div>
            <h1>历史留言</h1>
            <ul class="history">
                <li>
                    <p>
                        <span class="name">姓名</span>
                        <span class="time">2020-02-20</span>
                    </p>
                    <p class="content">3213132</p>
                </li>
            </ul>
        </div>

    </div>
</body>
<script src="./js/jquery-3.6.0.min.js"></script>
<script>
    let btn = $("button");
    btn.click(function(){
        //获取昵称
        let nickName = $(".nickName").val();
        let content = $(".textContent").val();
        let type = $('input:checkbox:checked').val();
        let history = $(".history");
        if(!nickName || !content){
            alert("信息不完整");
        }
        let time = new Date().toLocaleString();
        
        nickName = type ? '匿名' : nickName;
        let li = `<li>
                    <p>
                        <span class="name">${nickName}</span>
                        <span class="time">${time}</span>
                    </p>
                    <p class="content">${content}</p>
                </li>`;
        history.append(li);
    })
</script>
</html>